﻿namespace Dark_Core_Server.Models.User
{
    public static class UserHelper
    {
        /// <summary>
        /// 基于SimpleUserRecord(简单用户记录)创建一个用户稳定和资料文档
        /// </summary>
        /// <param name="userRecord"></param>
        /// <returns></returns>
        public static Tuple<UserDocument, UserProfileDocument> ToDocument(this SimpleUserRecord userRecord)
        {
            UserProfileDocument userProfileDocument = new UserProfileDocument();
            UserDocument userDocument = new UserDocument()
            {
                UserName = userRecord.username,
                Password = userRecord.password,
                ProfileId = userProfileDocument.id,
            };
            userProfileDocument.BasicId = userDocument.id;
            return new Tuple<UserDocument, UserProfileDocument>(userDocument, userProfileDocument);
        }

        /// <summary>
        /// zh-cn: 将字符串转换为UserQueryMode枚举类型
        /// </summary>
        /// <param name="queryStr">查询字符</param>
        /// <returns>用户查询模式</returns>
        public static UserQueryMode ToUserQueryMode(this string queryStr)
        {
            UserQueryMode result = queryStr.ToUpper() switch
            {
                "MULTIALL" => UserQueryMode.MultiAll,
                "MULTINICKNAME" => UserQueryMode.MultiNickname,
                "MULTILEVEL" => UserQueryMode.MultiLevel,
                "SINGLEID" => UserQueryMode.SingleId,
                "SINGLEUSERNAME" => UserQueryMode.SingleUsername,
                _ => UserQueryMode.MultiAll
            };
            return result;
        }

        /// <summary>
        /// zh-cn: 将UserDocument转换为SimpleUserRecord
        /// </summary>
        /// <param name="userDocument">用户文档</param>
        /// <returns>简单用户记录</returns>
        public static SimpleUserRecord ToSimpleUserRecord(this UserDocument userDocument) =>
            new SimpleUserRecord(userDocument.UserName, userDocument.Password);


        
    }
}
